package com.brspace.qualitycontrol.controller.admin;



import com.brspace.qualitycontrol.entity.Test;
import com.brspace.qualitycontrol.mapper.TestMapper;
import com.brspace.qualitycontrol.service.TestService;
import com.brspace.qualitycontrol.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 *  流程引擎
 * </p>
 *
 * @author Hugo
 * @since 2021-03-25
 */
@Api(description = "测试")
@RestController
@RequestMapping("/admin/process/test")
public class TestController {

    @Autowired
    private TestService testService;
    @Autowired
    private TestMapper testMapper;
    /**
     *
     *@author Hugo
     *@date 2021-03-25 14:30
     **/
    @PostMapping("save/{pId}")
    public R save(Test test, @PathVariable int pId){
        testService.saveTest(test,pId);
        return R.ok();
    }

    /**
     *@Description 获取所有数据
     *@Params []
     *@author Hugo
     *@date 2021-03-25 16:25
     *@return list
     **/
    @PostMapping("getInfo")
    public R getInfo(){
        return  R.ok().data("list",testMapper.selectList(null));
    }

    /**
     *@Description 获取信息
     *@Params [id]
     *@author Hugo
     *@date 2021-03-25 16:27
     *@return 查询数据
     **/
    @PostMapping("openInfo/{id}")
    public R openInfo(@PathVariable String id){
        return  R.ok().data("list",testMapper.selectById(id));
    }

    /**
     *@Description 审批流程
     *@Params [test]
     *@author Hugo
     *@date 2021-03-30 11:17
     *@return null
     **/
    @PostMapping("examine")
    public R examine(Test test){
        testService.examine(test);
        return R.ok();
    }

//    @PreAuthorize("hasRole('boss')")
    @ApiOperation("信息列表")
    @GetMapping("list/{uid}")
    public R list(@PathVariable String uid){
        return R.ok().data("list",testService.findAll(uid));
    }
}

